<template>
  <div class="test">
    <h1>测试页面</h1>
    <MindmapViewer v-if="testData" :data="testData" />
    <button @click="generateTest">生成测试</button>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import MindmapViewer from '../components/MindmapViewer.vue'

const testData = ref({
  root: {
    label: '测试需求',
    children: [
      {
        label: '模块1',
        children: [
          {
            label: '功能1',
            children: [
              { label: '测试点1' },
              { label: '测试点2' }
            ]
          }
        ]
      }
    ]
  }
})

const generateTest = async () => {
  console.log('调用生成测试用例API')
  try {
    const response = await fetch('/api/ai/generate-test-cases/', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        full_analysis_content: JSON.stringify(testData.value),
        case_name: '测试用例',
        project_id: null,
        version_id: null
      })
    })
    
    const data = await response.json()
    console.log('生成结果:', data)
  } catch (error) {
    console.error('错误:', error)
  }
}
</script>